package com.futures.investm.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.futures.investm.R;
import com.futures.investm.adapter.MessageAdapter;
import com.futures.investm.constant.BussConstant;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;

import java.util.List;

import tech.com.commoncore.base.BaseFragment;

public class NoticeFragment extends BaseFragment {
    MessageAdapter messageAdapter;
    RecyclerView mRecyclerview;
    public static NoticeFragment newInstance(){
        NoticeFragment fragment = new NoticeFragment();

        return fragment;
    }

    @Override
    public int getContentLayout() {
        return R.layout.fragment_notice;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mRecyclerview = (RecyclerView) mContentView.findViewById(R.id.rv_contentFastLib);
        mRecyclerview.setLayoutManager(new LinearLayoutManager(mContext));

        messageAdapter = new MessageAdapter();
        mRecyclerview.setAdapter(messageAdapter);


        AVQuery<AVObject> query = new AVQuery<>(BussConstant.TABLE_MESSAGE);
        query.setLimit(10);
        query.setSkip(0 * 10);
        query.orderByDescending("createdAt");
        query.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> list, AVException e) {
                // list 是一个 AVObject 的 List
                // list 指的就是所有包含当前 tag 的 TodoFolder
                if (e == null) {
//                    FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(), list, null);
                    messageAdapter.replaceData(list);
                } else {
//                    FastManager.getInstance().getHttpRequestControl().httpRequestError(getIHttpRequestControl(), e.getCode() + "", e.getMessage());
                }

            }
        });
    }
}
